home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr31 / uxarc.zip / UXARC.C next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  120 lines

  1. /*    uxarc.c
  2.  
  3.       Universal archive processing program.
  4.       Assumes PKPAK/PKUNPAK for .ARC files.
  5.               PKZIP/PKUNZIP for .ZIP files.
  6.               LHARC/LHARC   for .LZH files.
  7.  
  8.       Programmer:  Neil McAllister
  9.  
  10.       Source written by Neil McAllister.  Released
  11.       to the public domain for use without profit.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #define   ZIP       1
  18. #define   ARC       2
  19. #define   LZH       3
  20.  
  21.  
  22. int main( int argc, char *argv[] )
  23.   {
  24.     char filename[15];
  25.     char cmd_line[111];
  26.     unsigned char arcfile_arg = 0;
  27.     unsigned char x = 1;
  28.     unsigned char flag = 0;
  29.     
  30.     puts( "\nUXARC Universal Archive Extractor 1.0   Written by Neil McAllister" );
  31.     if ( argc == 1 )
  32.       {
  33.         puts( "  Usage: UXARC <options><arcfile>" );
  34.         puts( "  This program will take the place of separate calls to" );
  35.         puts( "  PKUNPAK, PKUNZIP, and LHARC." );
  36.         return 0;
  37.       }
  38.     while ( !arcfile_arg )
  39.       if ( argv[x][0] != '-'  &&  argv[x][0] != '/' )
  40.         arcfile_arg = x;
  41.       else
  42.         argv[x++][0] = '/';
  43.     if ( !arcfile_arg )
  44.       {
  45.         puts( "***** FATAL: No archive file specified on command line." );
  46.         return 1;
  47.       }
  48.     for ( x = 0; argv[arcfile_arg][x] != '\0'; x++ )
  49.       if ( argv[arcfile_arg][x] == '.' )
  50.         {
  51.           ++x;
  52.           if ( !strcmpi(&argv[arcfile_arg][x], "ZIP") )
  53.             {
  54.               flag = ZIP;
  55.               strcpy( cmd_line, "PKUNZIP" );
  56.             }
  57.           else
  58.             if ( !strcmpi(&argv[arcfile_arg][x], "ARC") )
  59.               {
  60.                 flag = ARC;
  61.                 strcpy( cmd_line, "PKUNPAK" );
  62.               }
  63.             else
  64.               if ( !strcmpi(&argv[arcfile_arg][x], "LZH") )
  65.                 {
  66.                   flag = LZH;
  67.                   strcpy( cmd_line, "LHARC" );
  68.                 }
  69.               else
  70.                 {
  71.                 puts( "***** FATAL: Unknown archive type on command line." );
  72.                   return 1;
  73.                 }
  74.         }
  75.     if ( !flag )
  76.       {
  77.         strcpy( filename, &argv[arcfile_arg][0] );
  78.         if ( fopen(strcat(filename, ".ZIP"), "r") != NULL )
  79.           {
  80.             flag = ZIP;
  81.             fcloseall();
  82.             strcpy( cmd_line, "PKUNZIP" );
  83.           }
  84.         else
  85.           {
  86.             strcpy( filename, &argv[arcfile_arg][0] );
  87.             if ( fopen(strcat(filename, ".ARC"), "r") != NULL )
  88.               {
  89.                 flag = ARC;
  90.                 fcloseall();
  91.                 strcpy( cmd_line, "PKUNPAK" );
  92.               }
  93.             else
  94.               {
  95.                 strcpy( filename, &argv[arcfile_arg][0] );
  96.                 if ( fopen(strcat(filename, ".LZH"), "r") != NULL )
  97.                   {
  98.                     flag = LZH;
  99.                     fcloseall();
  100.                     strcpy( cmd_line, "LHARC" );
  101.                   }
  102.                 else
  103.                   {
  104.                     puts( "***** FATAL: Could not open specified arcfile." );
  105.                     return 1;
  106.                   }
  107.               }
  108.           }
  109.       }
  110.     if ( argv[1][0] != '/'  &&  flag == LZH )
  111.       strcat( cmd_line, " /x" );
  112.     for ( x = 1; x < argc; x++ )
  113.       {
  114.         strcat( cmd_line, " " );
  115.         strcat( cmd_line, &argv[x][0] );
  116.       }
  117.     system( cmd_line );
  118.     return 0;
  119.   }
  120.